package com.example.projectjava.service;


import com.example.projectjava.dao.LogisticDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LogisticService {

    @Autowired
    LogisticDao logisticDao;//spring会自动将userDao注入到此类为(自动为该属性赋值)

    public  int insertLogistic(String dvy_id,String dvy_name,String company_home_url,String query_url){
        return logisticDao.insertLogistic(dvy_id,dvy_name,company_home_url,query_url);
    }

    public int deleteLogistic(String dvy_name) {
        int res = logisticDao.deleteLogistic(dvy_name);
        if (res <= 0) {
            throw new RuntimeException("该快递公司不存在");
        } else {
            return 1;
        }
    }

    public List<Map<String, Object>> queryAllLogistic() {
        return logisticDao.queryAllLogistic();
    }

    public int updateLogistic(String dvy_id, String dvy_name, String company_home_url, String query_url) {
        int res = logisticDao.updateLogistic(dvy_id, dvy_name, company_home_url, query_url);
        if (res <= 0) {
            throw new RuntimeException("该快递公司不存在");
        }
        return 1;
    }
}
